package membertask

import (
	"context"

	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"
	"mall/service/backend/api/internal/utils"
	"mall/service/backend/common/i18n"
	"mall/service/setting/rpc/settingclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetMemberTaskByIdLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetMemberTaskByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMemberTaskByIdLogic {
	return &GetMemberTaskByIdLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetMemberTaskByIdLogic) GetMemberTaskById(req *types.IDReq) (resp *types.MemberTaskInfoResp, err error) {
	data, err := l.svcCtx.SettingRpc.BackendGetMemberTaskById(l.ctx, &settingclient.IDReq{
		Id: req.Id,
	})
	if err != nil {
		return nil, err
	}

	option := utils.GetOptionByStatus(data.Status)

	return &types.MemberTaskInfoResp{
		BaseDataInfo: types.BaseDataInfo{
			Success: true,
			Msg:     l.svcCtx.Trans.Trans(l.ctx, i18n.Success),
		},
		Data: &types.MemberTaskInfo{
			BaseIDInfo: types.BaseIDInfo{
				Id:         data.Id,
				CreatedAt:  data.CreatedAt,
				UpdatedAt:  data.UpdatedAt,
				DeletedAt:  data.DeletedAt,
				CanAccept:  option.CanAccept,
				CanReject:  option.CanReject,
				CanRemove:  option.CanRemove,
				CanRestore: option.CanRestore,
			},
			Name:        data.Name,
			Slug:        data.Slug,
			Description: data.Description,
			Remark:      data.Remark,
			PicId:       data.PicId,
			PicUrl:      data.PicUrl,
			Gems:        data.Gems,
			Growth:      data.Growth,
			Integrals:   data.Integrals,
			Sort:        data.Sort,
			Status:      data.Status,
		},
	}, nil
}
